package cn.ezios.huo.biz.sxln.dao.service.impl;

import cn.ezios.huo.biz.sxln.dao.dto.LnMemberCaseDTO;
import cn.ezios.huo.biz.sxln.dao.vo.LnMemberCaseVo;
import com.baomidou.mybatisplus.core.conditions.AbstractWrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.ezios.huo.biz.sxln.dao.domain.LnMemberCase;
import cn.ezios.huo.biz.sxln.dao.service.LnMemberCaseService;
import cn.ezios.huo.biz.sxln.dao.mapper.LnMemberCaseMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

/**
 * @author wangjian
 * @description 针对表【ln_member_case(会员列表)】的数据库操作Service实现
 * @createDate 2024-07-22 17:02:25
 */
@Service
public class LnMemberCaseServiceImpl extends ServiceImpl<LnMemberCaseMapper, LnMemberCase>
        implements LnMemberCaseService {

    /**
     * 分页查询
     *
     * @param current
     * @param size
     * @param dto
     * @return
     */
    @Override
    public IPage<LnMemberCaseVo> queryPageWithDTO(Integer current, Integer size, LnMemberCaseDTO dto) {
        Page<LnMemberCase> pg = Page.of(current, size);
        AbstractWrapper<LnMemberCase, SFunction<LnMemberCase, ?>, LambdaQueryWrapper<LnMemberCase>> qw = this.lambdaQuery()
                .eq(dto.getMemberId() != null, LnMemberCase::getMemberId, dto.getMemberId())
                .like(dto.getRealName() != null, LnMemberCase::getRealName, dto.getRealName())
                .like(dto.getPenName() != null, LnMemberCase::getPenName, dto.getPenName())
                .eq(dto.getMemberType() != null, LnMemberCase::getMemberType, dto.getMemberType())
                .eq(dto.getSex() != null, LnMemberCase::getSex, dto.getSex())
                .like(dto.getRemark() != null, LnMemberCase::getRemark, dto.getRemark())

                .orderByDesc(LnMemberCase::getEntranceTime)
                .getWrapper();
        page(pg, qw);
        IPage<LnMemberCaseVo> results = pg.convert(orignal -> {
            LnMemberCaseVo vo = new LnMemberCaseVo();
            BeanUtils.copyProperties(orignal, vo);
            return vo;
        });
        return results;
    }

    /**
     * 判断会员是否重复
     *
     * @param memberId
     * @return
     */
    @Override
    public boolean isDuplication(String memberId) {
        return lambdaQuery().eq(LnMemberCase::getMemberId, memberId)
                .count() > 0;
    }

    /**
     * 根据id获取Vo
     *
     * @param id
     * @return
     */
    @Override
    public LnMemberCaseVo getVoById(String id) {
        LnMemberCase original = getById(id);
        if (original == null)
            return null;
        LnMemberCaseVo vo = new LnMemberCaseVo();
        BeanUtils.copyProperties(original, vo);
        return vo;
    }
}




